<template>
  <el-form
    :model="noticForm"
    ref="noticForm"
    label-width="80px"
    :inline="true"
    :rules="rules"
  >
    <el-card style="display: none">
      <h4 style="font-weight: 800">基本信息(第一行必填)</h4>
      <el-row :inline="true">
        <el-form-item label="表描述" prop="comment">
          {{ queryParams.comment }}
          <!-- <el-input
            v-model="queryParams.tableName"
            placeholder="请输入表名称"
            clearable
          /> -->
        </el-form-item>
        <el-form-item label="数据库表名" prop="tableName" label-width="100px">
          {{ queryParams.tableName }}
          <!-- <el-input
            v-model="queryParams.tableName"
            placeholder="请输入表名称"
            clearable
          /> -->
        </el-form-item>
        <el-form-item label="数据库名" prop="databaseName">
          {{ queryParams.databaseName }}
          <!-- <el-input v-model="form.databaseName" placeholder="请输入数据库名" /> -->
        </el-form-item>
        <el-form-item label="字符集" prop="characterSet">
          {{ queryParams.characterSet }}
        </el-form-item>
        <el-form-item label="引擎" prop="engine">
          {{ queryParams.engine }}
          <!-- <el-input v-model="form.engine" placeholder="请输入引擎" /> -->
        </el-form-item>
        <el-form-item label="注释" prop="comment">
          {{ queryParams.comment }}
          <!-- <el-input v-model="form.comment" placeholder="请输入注释" /> -->
        </el-form-item>
        <el-form-item label="索引字段" prop="indexFields">
          {{ queryParams.indexFields }}
        </el-form-item>
        <!-- <el-form-item label="表描述" prop="tableName">
          <el-input
            v-model="queryParams.tableName"
            placeholder="请输入表描述"
            clearable
          />
        </el-form-item> -->
        <!-- <el-form-item label="实体类名称" prop="supplier" label-width="90px">
          <el-input
            v-model="queryParams.supplier"
            placeholder="请输入实体类名称"
            clearable
          />
        </el-form-item> -->
        <!-- <el-form-item label="备注" prop="remark">
          <el-input
            v-model="queryParams.remark"
            placeholder="请输入备注"
            clearable
          />
        </el-form-item> -->
      </el-row>
    </el-card>

    <!-- 添加或修改产品二级信息对话框 :on-change="handleChange"-->
    <el-dialog
      title="导入"
      :visible.sync="dialogVisible"
      width="500px"
      append-to-body
      v-if="dialogVisible"
    >
      <!-- 文件上传-->
      <el-form
        :rules="rules"
        :model="dataForm"
        ref="dataForm"
        label-width="150px"
        @submit.native.prevent
      >
        <el-form-item label="文件：" prop="file">
          <el-upload
            class="upload-import"
            ref="uploadImport"
            :http-request="httpRequest"
            action=""
            :on-remove="handleRemove"
            :file-list="fileList"
            :limit="1"
            :on-change="handleChange"
            :auto-upload="false"
            :before-upload="beforeAvatarUpload"
          >
            <!--
            accept="application/zip,.zip" 设置接收的文件类型-->
            <el-button
              v-show="!hasFile"
              slot="trigger"
              size="small"
              type="primary"
              >选取文件</el-button
            >
            <!-- <div slot="tip" class="el-upload__tip">
          只能上传zip文件，且不超过10M
        </div> -->
          </el-upload>
          <!-- 关闭自动上传-->
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submitUpload">提交</el-button>
          <!-- <el-button @click="resetForm('ruleForm')">重置</el-button> -->
          <el-button @click="dialogVisible = false">取 消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- 添加或修改菜单对话框 -->
    <el-dialog :visible.sync="openTable" width="1800px" append-to-body>
      <selectTableField @trackingNumberHandle="trackingNumberHandle" />
    </el-dialog>

    <el-card>
      <div slot="header" style="justify-content: space-between; display: flex">
        <span><i class="el-icon-collection"></i> 字段信息</span>
        <!-- <span>
          <el-col :span="1.5">
            <el-button
              type="primary"
              size="mini"
              plain
              @click="openTable = true"
            >
              从表中选
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="primary"
              size="mini"
              plain
              icon="el-icon-upload"
              @click="daoru"
              >以文件导入</el-button
            >
          </el-col>
        </span> -->
      </div>
      <div class="el-dialog-div">
        <el-col :span="24">
          <el-row
            v-for="(noticItem, index) in noticForm.noticConfig"
            :key="index"
          >
            <el-col
              :span="21"
              v-for="nameItem in noticItem.name"
              :key="nameItem.key"
            >
              <el-form-item prop="" label="">
                <el-input
                  :disabled="true"
                  v-model="nameItem.comment"
                  placeholder="请输入字段描述"
                  style="width: 200px"
                  @blur="handleName(nameItem)"
                />
                <el-input
                  :disabled="true"
                  v-model="nameItem.columnName"
                  placeholder="请输入字段列名"
                  style="width: 200px"
                />
                <el-button
                  type="primary"
                  size="mini"
                  @click="addComment(nameItem)"
                  >添加到对话框</el-button
                >
              </el-form-item>

              <!--
                 @click="addDomain(noticItem)"

                <el-select
                  v-model="nameItem.columnType"
                  clearable
                  placeholder="请输入物理类型"
                  style="width: 150px"
                >
                  <el-option
                    v-for="(val, i) in columnTypeList"
                    :key="i"
                    :label="val"
                    :value="val"
                  />
                </el-select>

                <el-input
                  v-show="false"
                  :disabled="nameItem.columnType != 'varchar'"
                  v-model="nameItem.typeLength"
                  placeholder="请输入长度"
                  style="width: 150px"
                />
              
              <el-form-item
                prop="isNullable"
                label="是否为空"
                label-width="80px"
              >
                <el-radio-group
                  v-model="nameItem.isNullable"
                  size="small"
                  fill="#66b1ff"
                >
                  <el-radio :label="0">是</el-radio>
                  <el-radio :label="1">否</el-radio>
                </el-radio-group>
              </el-form-item>
              <el-form-item
                prop="isPrimary"
                label="是否主键"
                label-width="80px"
              >
                <el-radio-group
                  v-model="nameItem.isPrimary"
                  size="small"
                  fill="#66b1ff"
                >
                  <el-radio :label="0">是</el-radio>
                  <el-radio :label="1">否</el-radio>
                </el-radio-group>
              </el-form-item>
              <el-form-item
                prop="isAutoIncrement"
                label="是否自增"
                label-width="80px"
              >
                <el-radio-group
                  v-model="nameItem.isAutoIncrement"
                  size="small"
                  fill="#66b1ff"
                >
                  <el-radio :label="0">是</el-radio>
                  <el-radio :label="1">否</el-radio>
                </el-radio-group>
              </el-form-item> -->
            </el-col>
            <!-- <el-col :span="3">
              <el-button
                type="primary"
                size="mini"
                @click="addDomain(noticItem)"
                >新增</el-button
              >
              <el-button
                type="danger"
                size="mini"
                @click.prevent="removeDomain(noticItem)"
                >删除</el-button
              >
            </el-col> -->
          </el-row>
        </el-col>
      </div>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="pageReq.pageNum"
        :limit.sync="pageReq.pageSize"
        @pagination="getList"
      />
    </el-card>

    <el-form-item style="width: 100%; text-align: center">
      <!-- <el-button @click="submitlive('noticForm')" type="primary"
        >提交</el-button
      > -->
      <!-- <el-button
        @click="handleGo('/biTool/SysTableData')"
        style="margin-left: 10px"
        >返回</el-button
      > -->
    </el-form-item>
  </el-form>
</template>
<script>
import {
  listSysTableField,
  addFieldList,
  delSysTableField,
} from "@/api/conf/SysTableField";
import { createTable, dropTableField } from "@/api/conf/SysTableData";
import {
  listBiZhiPuApi,
  updateAttributes,
} from "@/api/conf/BiTableColAttributes";
//--------导入token
import { getToken } from "@/utils/auth";
import AddressParse from "address-parse";
//数据获取
import { pcaa } from "area-data";
import axios from "axios";
const util = require("@/api/sample/util.js");
// import { province } from '@/api/sample/map'
import { productNoLike } from "@/api/product/template";
import { productNoColorLike, listAll, colorLike } from "@/api/product/secondry";
import {
  SampleTalentFirstAdd,
  SampleGiftBatchApply,
  inventory,
} from "@/api/sample/sample";
import Addcontact from "@/views/sample/contact/Addcontact.vue";
import selectTableField from "@/views/conf/SysTableField/select.vue";

export default {
  name: "Selfacting",
  props: {
    row: {
      type: Object,
      default: () => {},
    },
  },
  dicts: [
    "sys_product_qudao",
    "sys_product_size",
    "sys_product_coder",
    "sys_sample_sf",
    "sys_one_zero",
    "sys_sample_status",
    "sys_sample_name",
    "sys_sample_cj",
    "sys_jst_sample_sf",
    "sys_sample_type",
  ],
  components: {
    Addcontact,
    selectTableField,
  },
  data() {
    return {
      total: 0,
      pageReq: {
        pageNum: 1,
        pageSize: 10,
      },
      openTable: false,
      columnTypeList: [
        "double",
        "int",
        "bigint",
        "varchar",
        "date",
        "datetime",
        "text",
      ],
      variableName: "访客",
      queryParams: {},
      iscontactList: false,
      sampleTalentCooperateType: "",
      innerApplyReason: "寄供应商",
      fLive: {
        isReturn: "否",

        expressCompany: "中通快递",
        productNum: 1,
      },
      count: 1,
      sizeArr: [],
      //库存量
      num: "",
      demo: "",
      //省市区
      pcaaData: pcaa,
      // 区域数据
      provinces: pcaa["86"],
      citys: [],
      areas: [],
      //
      productNo: "",
      colorProperty: "",
      size: "",
      // 遮罩层
      loading: true,
      //模糊匹配
      sizeList: [],
      ColorLike: [],
      options: [], // 选项，从后端传递过来
      sampleTalentCooperateType: "",
      expressCompany: "中通快递",
      //data
      noticForm: {
        noticConfig: [
          {
            name: [
              {
                columnName: "",
                comment: "",
                columnType: "",
                typeLength: "",
                isNullable: 1,
                isPrimary: 1,
                isAutoIncrement: 1,

                // receiverDistrict: "",
                // address: "",
                // value: "",
                // phone: "",
                // productNo: "",
                // colorProperty: "",
                // size: "",
                // productNum: "",
                // isReturn: "是",
                // id: 0,

                // expressCompany: "",
              },
            ],
            // phone: [
            //     {
            //         value: "",
            //     },
            // ],
          },
        ],
      },

      sampleTalentContact: {
        phone: "",
        receiverCity: "",
        receiverDistrict: "",
        receiverState: "",
        recipient: "",
        address: "",
      },
      sampleTalentInfo: {
        platform: "",
        platformId: "",
        talentLevel: "",
        xhsNickname: "",
        contactPerson: "",
        recommendSituation: "",
        reason: "",
        homeLink: "",
        fansNum: "",
        likeNum: "",
        cooperatePrice: "",
        talentStatus: "",
        contactWechat: "",
      },
      sampleTalentPay: {
        payAccount: "",
        payImage: "",
        payMethod: "",
        payName: "",
        platform: "",
      },

      // fileLi: [],
      // dialogVisible: false,
      // limit: 2,
      // Upload: {
      //   // 设置上传的请求头部
      //   headers: {
      //     header: { responseType: "blob" },

      //     Authorization: "Bearer " + getToken(),
      //   },
      //   // 图片上传的方法地址:
      //   url: process.env.VUE_APP_BASE_API + "/conf/SysTableField/importFile",
      // },

      hasFile: false,
      fileList: [],
      dialogVisible: false,
      pjtUrl: process.env.VUE_APP_BASE_API,
      dataForm: {
        file: null,
      },

      // 表单校验
      rules: {
        productNo: [
          { required: true, message: "货号不能为空", trigger: "blur" },
        ],
        colorProperty: [
          { required: true, message: "颜色不能为空", trigger: "blur" },
        ],
        size: [{ required: true, message: "尺寸不能为空", trigger: "blur" }],
        // productNum: [
        //     { required: true, message: "数量不能为空", trigger: "blur" }
        // ],
        // platform: [
        //     { required: true, message: "平台名称不能为空", trigger: "blur" }
        // ],
        // platformId: [
        //     { required: true, message: "平台ID不能为空", trigger: "blur" }
        // ],
        // xhsNickname: [
        //     { required: true, message: "昵称不能为空", trigger: "blur" }
        // ],
        // phone: [
        //     { required: true, message: "电话不能为空", trigger: "blur" }
        // ],
      },
    };
  },
  watch: {
    row: {
      handler: function (newnew, oldold) {
        console.log("newnew", newnew);
        if (JSON.stringify(this.row) != "{}") {
          this.queryParams = this.row;
          this.getList();
        }
      },
      deep: true,
      immediate: true,
    },
  },
  // created() {
  //   // console.log(JSON.stringify(this.$route.query.obj));
  //   if (this.$route.query.obj) {
  //     this.queryParams = this.$route.query.obj;
  //     console.log(JSON.stringify(this.queryParams));
  //     this.getList();
  //   }

  //   // this.provincearr = province
  // },
  methods: {
    addComment(nameItem) {
      this.$emit("addComment", nameItem.comment);
    },
    /** 查询表字段信息列表 */
    getList() {
      listSysTableField({
        tableName: this.queryParams.tableName,
        ...this.pageReq,
      }).then((response) => {
        if (response.rows.length > 0) {
          this.total = response.total;
          this.noticForm.noticConfig = [];
          response.rows.forEach((item) => {
            this.noticForm.noticConfig.push({
              name: [
                {
                  ...item,
                  isEdit: true,
                },
              ],
            });
          });
        }
      });
    },
    handleName(nameItem) {
      if (!nameItem.comment) {
        return;
      }
      this.openLoading();
      listBiZhiPuApi({ variableName: nameItem.comment }).then((response) => {
        this.$modal.closeLoading();
        nameItem.columnName = response.variableMysql;
        nameItem.columnType = response.variableType;
        nameItem.typeLength = response.variableLength;
      });
    },
    // addText() {
    //   if (!this.demo) {
    //     this.$modal.msgError("请输入内容");
    //     return;
    //   }

    //   let address = this.demo.replace(/\s+/g, " ");
    //   console.log(JSON.stringify(address));
    //   axios({
    //     method: "get",
    //     url: "https://v.api.aa1.cn/api/api-kdjx/index.php",
    //     params: {
    //       msg: address,
    //     },
    //   }).then((res) => {
    //     console.log(JSON.stringify(res.data));
    //     let m = res.data.newslist[0];
    //     this.sampleTalentContact.phone = m.mobile ? m.mobile : "";
    //     this.sampleTalentContact.recipient = m.name ? m.name : "";
    //     this.sampleTalentContact.receiverState = m.province ? m.province : "";
    //     this.sampleTalentContact.receiverCity = m.city ? m.city : "";
    //     this.sampleTalentContact.receiverDistrict = m.district
    //       ? m.district
    //       : "";
    //     this.sampleTalentContact.address = m.detail;

    //     this.seletekey(this.sampleTalentContact.receiverState, "province");
    //     this.seletekey(this.sampleTalentContact.receiverCity, "city");
    //     this.seletekey(this.sampleTalentContact.receiverDistrict, "area");
    //   });
    // },
    handleGo(path) {
      this.$router.push({
        path: path,
      });
    },
    trackingNumberHandle(list) {
      console.log(JSON.stringify(list));
      var apply = this.noticForm.noticConfig.map((item) => item.name[0]);
      // let idsSet = this.areIdsInFirstArray(apply, list);
      // if (idsSet) {
      //   this.$modal.msgError("数据重复");
      //   return;
      // }
      this.openTable = false;
      // this.noticForm.noticConfig = [];
      // list.forEach((item) => {
      //   this.noticForm.noticConfig.push({
      //     name: [
      //       {
      //         ...item,
      //       },
      //     ],
      //   });
      if (!apply[0].comment) {
        this.noticForm.noticConfig = [];
        list.forEach((item) => {
          this.noticForm.noticConfig.push({
            name: [
              {
                ...item,
                isEdit: true,
              },
            ],
          });
        });
      } else {
        list.forEach((item) => {
          this.noticForm.noticConfig.push({
            name: [
              {
                ...item,
                isEdit: true,
              },
            ],
          });
        });
      }
      // });
    },
    //判重
    areIdsInFirstArray(arr1, arr2) {
      // 使用 Set 存储第一个数组中所有唯一的 id
      const idsSet = new Set(arr1.map((item) => item.id));

      // 使用 Array.prototype.every 来检查第二个数组中的每个 id 是否都在 Set 中
      return arr2.every((item) => idsSet.has(item.id));
    },
    addText() {
      if (!this.demo) {
        this.$modal.msgError("请输入内容");
        return;
      }

      let address = this.demo.replace(/\s+/g, " ");
      console.log(JSON.stringify(address));
      const result = AddressParse.parse(address);
      var apply = this.noticForm.noticConfig.map((item) => item.name[0]);
      if (!apply[0].recipient) {
        this.noticForm.noticConfig = [];
        this.noticForm.noticConfig.push({
          name: [
            {
              recipient: result[0].name ? result[0].name : "",
              phone: result[0].mobile ? result[0].mobile : "",
              receiverState: result[0].province ? result[0].province : "",
              receiverCity: result[0].city ? result[0].city : "",

              receiverDistrict: result[0].area ? result[0].area : "",
              address: result[0].details,
              //   key: Date.now(),
              createBy: null,
              createTime: null,
              id: null,
              isDelete: null,
              platform: null,
              platformId: null,
              remark: null,
              sampleTalentInfold: null,
              updateBy: null,
              updateTime: null,
              xhsNickname: null,
            },
          ],
        });
      } else {
        this.noticForm.noticConfig.push({
          name: [
            {
              recipient: result[0].name ? result[0].name : "",
              phone: result[0].mobile ? result[0].mobile : "",
              receiverState: result[0].province ? result[0].province : "",
              receiverCity: result[0].city ? result[0].city : "",

              receiverDistrict: result[0].area ? result[0].area : "",
              address: result[0].details,
              //   key: Date.now(),
              createBy: null,
              createTime: null,
              id: null,
              isDelete: null,
              platform: null,
              platformId: null,
              remark: null,
              sampleTalentInfold: null,
              updateBy: null,
              updateTime: null,
              xhsNickname: null,
            },
          ],
        });
      }
      return;
      this.sampleTalentContact.phone = result[0].mobile ? result[0].mobile : "";
      this.sampleTalentContact.recipient = result[0].name ? result[0].name : "";
      this.sampleTalentContact.receiverState = result[0].province
        ? result[0].province
        : "";
      this.sampleTalentContact.receiverCity = result[0].city
        ? result[0].city
        : "";
      this.sampleTalentContact.receiverDistrict = result[0].area
        ? result[0].area
        : "";
      this.sampleTalentContact.address = result[0].details;

      this.seletekey(this.sampleTalentContact.receiverState, "province");
      this.seletekey(this.sampleTalentContact.receiverCity, "city");
      this.seletekey(this.sampleTalentContact.receiverDistrict, "area");

      let obj = {
        fullAddress: this.demo,
        province: this.sampleTalentContact.receiverState,
        city: this.sampleTalentContact.receiverCity,
        district: this.sampleTalentContact.receiverDistrict,
        detailedAddress: this.sampleTalentContact.address,

        recipientPhone: this.sampleTalentContact.phone,
        recipientName: this.sampleTalentContact.recipient,
      };

      axios({
        method: "post",
        url: "http://47.107.129.160:9001/prod-api/product/parsing",
        // url: "http://47.97.123.182:1399/smAddress",
        data: obj,
      }).then((response) => {});
      //   this.sampleTalentContact.phone = res.data.phone ? res.data.phone : "";
      //   this.sampleTalentContact.recipient = res.data.name ? res.data.name : "";
      //   this.sampleTalentContact.receiverState = res.data.province
      //     ? res.data.province
      //     : "";
      //   this.sampleTalentContact.receiverCity = res.data.city
      //     ? res.data.city
      //     : "";
      //   this.sampleTalentContact.receiverDistrict = res.data.county
      //     ? res.data.county
      //     : "";
      //   this.sampleTalentContact.address = res.data.street
      //     ? res.data.street + res.data.address
      //     : res.data.address;

      //   this.seletekey(this.sampleTalentContact.receiverState, "province");
      //   this.seletekey(this.sampleTalentContact.receiverCity, "city");
      //   this.seletekey(this.sampleTalentContact.receiverDistrict, "area");
      // });
    },
    testsampleTalentCooperateType(val) {
      console.log(val);
      this.sampleTalentCooperateType = val;
    },
    postcreateTable() {
      createTable(this.queryParams.tableName).then((response) => {
        if (response.code == 200) {
          this.$modal.msgSuccess("创建表成功");
          this.$router.push({
            path: "/conf/SysTableData",
          });
        }
      });
    },
    hasDuplicateVariableNames(array) {
      const variableNameSet = new Set();
      for (const item of array) {
        if (variableNameSet.has(item.columnName)) {
          // 如果已经存在相同的variableName，则返回true
          return true;
        }
        // 否则，将variableName添加到集合中
        variableNameSet.add(item.columnName);
      }
      // 如果没有发现重复的variableName，则返回false
      return false;
    },
    submitlive() {
      console.log(JSON.stringify(this.noticForm.noticConfig));

      // this.noticForm.noticConfig.forEach(item => {
      //     note.push(item.name)
      // })
      var apply = this.noticForm.noticConfig.map((item) => item.name[0]);
      if (this.hasDuplicateVariableNames(apply)) {
        this.$modal.msgError("字段重复，请删掉重复项");
        return;
      }
      var variableName = [];
      var FieldList = [];

      apply.forEach((item) => {
        variableName.push({
          variableName: item.comment,
          variableType: item.columnType,
          variableMysql: item.columnName,
        });
        if (!item.tableName) {
          item.tableName = this.queryParams.tableName;
        }
        if (item.columnType != "varchar") {
          delete item.typeLength;
        }
      });
      console.log(JSON.stringify(variableName));
      updateAttributes(variableName).then((response) => {});

      addFieldList(apply).then((response) => {
        this.getList();
        if (response.code == 200) {
          this.$modal.msgSuccess("提交成功");
        }
      });

      return;
      var live = [
        {
          ...this.fLive,
          innerApplyReason: this.innerApplyReason,
          expressCompany: this.expressCompany,
          id: null,
        },
      ];

      console.log(JSON.stringify(live));
      var liveList = {
        sampleTalentCooperateType: this.sampleTalentCooperateType,
        sampleTalentApplyVOList: live,
        sampleTalentContactList: apply,
        // sampleTalentContact: { ...this.sampleTalentContact },
        // sampleTalentInfo: { ...this.sampleTalentInfo },
        // sampleTalentPay: { ...this.sampleTalentPay },
      };
      if (!liveList.sampleTalentApplyVOList[0].productNo) {
        this.$modal.msgError("请选择款式");
        return;
      }
      // if (!liveList.sampleTalentApplyVOList[0].colorProperty) {

      //     this.$modal.msgError('请选择颜色')
      //     return
      // }
      // if (!liveList.sampleTalentApplyVOList[0].size) {

      //     this.$modal.msgError('请选择尺寸')
      //     return
      // }
      // if (!liveList.sampleTalentApplyVOList[0].productNum) {

      //     this.$modal.msgError('请输入数量')
      //     return
      // }
      // if (!liveList.sampleTalentApplyVOList[0].isReturn) {

      //     this.$modal.msgError('请选择是否归还')
      //     return
      // }
      if (liveList.sampleTalentApplyVOList[1]) {
        if (!liveList.sampleTalentApplyVOList[1].productNo) {
          this.$modal.msgError("请选择第二个款式");
          return;
        }
      }

      // return
      console.log(JSON.stringify(liveList));
      SampleGiftBatchApply(liveList).then((res) => {
        console.log(res);
        if (res.msg == "操作完成！") {
          this.$modal.msgSuccess("操作完成");
          // this.data = {};
          // window.location.reload();
          //清空数据
          this.resetForm();

          this.$router.push({
            path: "/sample/sampleApply",
            // query: { platformId: this.sampleTalentInfo.platformId },
          });
          // location.reload();
        } else {
          this.$modal.msgError(res.msg);
        }
      });
    },
    resetForm() {
      this.noticForm = {
        noticConfig: [
          {
            name: [
              {
                productNo: "",
                colorProperty: "",
                size: "",
                productNum: "",
                isReturn: "是",
                id: 0,
              },
            ],
          },
        ],
      };
      this.sampleTalentContact = {};
      this.sampleTalentInfo = {};
      this.sampleTalentPay = {};
    },
    submitnote() {
      var apply = this.noticForm.noticConfig.map((item) => item.name[0]);
      console.log(JSON.stringify(apply));

      var live = [];
      apply.forEach((item) => {
        live.push({ expressCompany: this.expressCompany, ...item });
      });

      var liveList = {
        sampleTalentCooperateType: "note",
        sampleTalentApplyVOList: live,
        sampleTalentContact: { ...this.sampleTalentContact },
        sampleTalentInfo: { ...this.sampleTalentInfo },
        sampleTalentPay: { ...this.sampleTalentPay },
      };
      console.log(JSON.stringify(liveList));
      if (!liveList.sampleTalentApplyVOList[0].productNo) {
        this.$modal.msgError("请选择款式");
        return;
      }
      // if (!liveList.sampleTalentApplyVOList[0].colorProperty) {

      //     this.$modal.msgError('请选择颜色')
      //     return
      // }
      // if (!liveList.sampleTalentApplyVOList[0].size) {

      //     this.$modal.msgError('请选择尺寸')
      //     return
      // }
      // if (!liveList.sampleTalentApplyVOList[0].productNum) {

      //     this.$modal.msgError('请输入数量')
      //     return
      // }
      // if (!liveList.sampleTalentApplyVOList[0].isReturn) {

      //     this.$modal.msgError('请选择是否归还')
      //     return
      // }
      if (liveList.sampleTalentApplyVOList[1]) {
        if (!liveList.sampleTalentApplyVOList[1].productNo) {
          this.$modal.msgError("请选择第二个款式");
          return;
        }
      }
      // return
      SampleTalentFirstAdd(liveList).then((res) => {
        console.log(res);
        if (res.msg == "操作完成！") {
          this.$modal.msgSuccess("操作完成");
          this.$router.push({
            path: "/sample/sample",
            // query: { platformId: this.sampleTalentInfo.platformId },
          });
        } else {
          this.$modal.msgError(res.msg);
        }
      });
    },

    // 新增
    removeDomain(item) {
      console.log(JSON.stringify(item));
      if (item.name[0].id) {
        let obj = {
          ...this.queryParams,
          fieldId: item.name[0].id,
        };
        this.$modal
          .confirm('是否确认删除编号为"' + item.name[0].id + '"的数据项？')
          .then(function () {
            return dropTableField(obj);
          })
          .then(() => {
            var index = this.noticForm.noticConfig.indexOf(item);

            this.noticForm.noticConfig.splice(index, 1);
            this.$modal.msgSuccess("删除成功");
          })
          .catch(() => {});
      } else {
        var index = this.noticForm.noticConfig.indexOf(item);

        this.noticForm.noticConfig.splice(index, 1);
      }
    },
    // 表单新增
    addDomain(item) {
      this.noticForm.noticConfig.push({
        name: [
          {
            columnName: "",
            comment: "",
            columnType: "",
            typeLength: "",
            isNullable: 0,
            isPrimary: 1,
            isAutoIncrement: 1,
            isEdit: false,
          },
        ],
        // phone: [
        //     {
        //         value: "",
        //         key: Date.now() + "2",
        //     },
        // ],
      });
    },
    getinput() {
      console.log(JSON.stringify(this.noticForm.noticConfig));
    },
    //修改对话框
    /* 获取颜色列表 */
    getSize(key) {
      console.log(JSON.stringify(key));
      // this.loading = true;
      // return
      // listAll({ productNo: this.form.productNo, colorProperty: this.form.colorProperty }).then((res) => {
      //     // this.loading = false;
      //     this.sizeList = res
      //     console.log(JSON.stringify(res));
      // });
    },

    /* 获取颜色列表 */
    getData(key) {
      console.log(JSON.stringify(key));
      // this.loading = true;
      // return
      // colorLike(key).then((res) => {
      //     // this.loading = false;
      //     this.ColorLike = res.data;
      //     console.log(JSON.stringify(this.ColorLike));
      // });
    },
    getinventory() {
      inventory({
        productNo: this.productNo,
        colorProperity: this.colorProperty,
        size: this.form.size,
      }).then((res) => {
        // console.log(JSON.stringify(res.data));
        if (res.code == 200) {
          this.num = res.data[0].virtual_qty;
        } else {
          this.$modal.msgError(res.msg);
        }
      });
    },
    testNum(index) {
      // this.num = JSON.parse(localStorage.getItem("num"))
    },
    testSize(key, index) {
      console.log(JSON.stringify(key));
      this.size = key;
      // console.log(this.count);
      console.log(index);
      inventory({
        productNo: this.productNo,
        colorProperity: this.colorProperty,
        size: this.size,
      }).then((res) => {
        if (res.code == 200) {
          if (res.data.length > 0) {
            this.sizeArr[index] = res.data[0].publicCanUseNum;
            console.log(JSON.stringify(this.sizeArr[index]));
            console.log(JSON.stringify(this.sizeArr));
            this.$forceUpdate();
          } else {
            this.$modal.msgError("该商品编码聚水潭不存在，请核对。");
          }
        } else {
          this.$modal.msgError(res.msg);
        }
      });
    },
    /* 获取尺寸列表 */
    testColor(productNo, colorProperty) {
      listAll({ productNo: productNo, colorProperty: colorProperty }).then(
        (res) => {
          // this.loading = false;
          this.sizeList = res;
          console.log(JSON.stringify(res));
        }
      );
    },
    /* 获取颜色列表 */
    testAdd(key) {
      this.productNo = key;
      console.log();
      if (!key) {
        return;
      }
      productNoColorLike({ productNo: key }).then((res) => {
        // this.loading = false;
        this.ColorLike = res.data;
        console.log(JSON.stringify(this.ColorLike));
      });
    },

    /* 获取货号列表 */
    getDatas(key) {
      console.log(JSON.stringify(key));
      this.loading = true;
      // return
      productNoLike(key).then((res) => {
        this.loading = false;
        this.options = res.data;
        console.log(JSON.stringify(this.options));
      });
    },
    //修改对话框
    //添加颜色列表获得焦点
    onFocus() {
      this.getData();

      this.getSize();
      // if (!this.form.colorProperty) {
      //     this.$selectRef.value.blur() //就是这一句，
      // }
    },
    seletekey(e, type) {
      if (e) {
        switch (type) {
          case "province":
            Object.keys(this.provinces).filter((item) => {
              if (this.provinces[item] === e) {
                this.citys = this.pcaaData[item];
              }
            });
            break;
          case "city":
            Object.keys(this.citys).filter((item) => {
              if (this.citys[item] === e) {
                this.areas = this.pcaaData[item];
              }
            });
            break;
          case "area":
            this.sampleTalentContact.receiverDistrict = e;
            this.$forceUpdate();
            break;
        }
      }
    },
    //图片上传前的相关判断
    beforeAvatarUpload(file) {
      // const isJPG = file.type == 'image/jpeg' || file.type == 'image/png';
      const isLt2M = file.size / 1024 / 1024 < 100;
      // if (!isJPG) {
      //     this.$message.error('上传头像图片只能是 JPG/PNG 格式!');
      // }
      if (!isLt2M) {
        this.$message.error("上传导入文件大小不能超过 100MB!");
      }

      return isLt2M;
    },
    handleRemove(file, fileList) {
      if (!fileList.length) {
        this.hasFile = false;
      }
      this.dataForm.file = null;
    },
    handleChange(file, fileList) {
      if (fileList.length >= 2) {
        return;
      }
      if (fileList.length === 1) {
        this.hasFile = true;
      }
      this.dataForm.file = file;
    },
    //确定按钮
    //调用组件upload的submit方法，从而触发httpRequest方法，实现手动上传
    submitUpload() {
      this.$refs["dataForm"].validate((valid) => {
        if (valid) {
          this.$refs.uploadImport.submit();
        }
      });
    },
    httpRequest(param) {
      // if (this.dataForm.name.length < 3) {
      //   this.$modal.msgWarning("请选择到店铺");
      //   return;
      // }
      let fd = new FormData();
      fd.append("file", param.file); // 传文件
      // fd.append("tableName", this.queryParams.tableName);
      // fd.append("brand", this.dataForm.name[0]);
      // fd.append("channel", this.dataForm.name[1]);
      //dataPar.file.raw
      console.log(JSON.stringify(fd));
      this.openLoading();
      axios
        .post(
          process.env.VUE_APP_BASE_API +
            "/conf/SysTableField/importFile?tableName=" +
            this.queryParams.tableName,
          fd,
          {
            headers: {
              header: { responseType: "blob" },

              Authorization: "Bearer " + getToken(),
              "Content-Type": "multipart/form-data",
            }, //定义内容格式,很重要
            // // timeout: 20000,
          }
        )
        .then((response) => {
          this.$modal.closeLoading();
          console.log(response);
          if (response.data) {
            this.dialogVisible = false;

            this.$modal.msgSuccess("导入成功");
            this.hasFile = false;
            var apply = this.noticForm.noticConfig.map((item) => item.name[0]);
            if (!apply[0].comment) {
              this.noticForm.noticConfig = [];
              response.data.forEach((item) => {
                this.noticForm.noticConfig.push({
                  name: [{ ...item }],
                });
              });
            } else {
              response.data.forEach((item) => {
                this.noticForm.noticConfig.push({
                  name: [{ ...item }],
                });
              });
            }
          } else {
            this.$modal.msgError("导入失败");
          }
        });
    },
    changecascadeList(value) {
      console.log(JSON.stringify(value));
    },
    //部门文件导入修改打开
    daoru() {
      this.dialogVisible = true;
    },
    // 打开加载层
    openLoading() {
      this.$modal.loading("正在加载，请稍候！");
    },
  },
};
</script>
<style lang="scss" scoped>
.el-dialog-div {
  height: 60vh;
  overflow-x: hidden;
}
</style>
@Excel(name ="表id")
private Long tableName;
/** 列名 */
@Excel(name ="列名")
private String columnName;
/** 数据类型 */@Excel(name ="数据类型")private string columnType
/** 长度 */
@Excel(name =“长度")
private Integer typeLength;
/** 是否为空 *@Excel(name ="是否为空")private Integer isNullable;
/** 是否主键 */
@Excel(name =“是否主键")
private Integer isPrimary,
/** 是否自增 */@Excel(name =“是否自增")private Integer isAutoIncrement;
/** 注释 */
@Excel(name =“注释")private string comment;